home *** CD-ROM | disk | FTP | other *** search
- #define STRICT
-
- // Includes standard Windows
- #include <windows.h>
- #include <windowsx.h>
- #include <time.h>
- #include <stdlib.h>
- #include <malloc.h>
- #include <memory.h>
- #include <stdio.h>
-
- // Includes D3D
- #define D3D_OVERLOADS
- #include <ddraw.h>
- #include <d3d.h>
- #include <d3dx.h>
-
- // Includes utilitaires D3D
- #include "d3dmath.h"
- #include "d3dutil.h"
- #include "D3DEnum.h"
-
- // Ids Resources
- #include "resource.h"
-
- // Constantes
- #include "const.h"
-
- // Types
- #include "types.h"
-
- // Variables globales projet
- #include "vars.h"
-
- // Prototypes fonctions autres modules
- #include "proto.h"
-
- // Macros
- #include "macros.h"
-
- // Variables statiques au module
- static D3DCOLOR cbAmbient, cbBack;
- static SCROLLINFO Si;
-
- // Gestion du dialog éclairage général
- BOOL CALLBACK bGlobLightDlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
- {
- int wmId, wmEvent, nScrollCode, nPos;
- HWND hwndScrollBar;
-
- Si.cbSize = sizeof(Si);
-
- switch( uMsg )
- {
- case WM_COMMAND :
- wmId = LOWORD(wParam); // Remember, these are...
- wmEvent = HIWORD(wParam); // ...different for Win32!
-
- switch (wmId)
- {
- case IDRESET: // Restaurer les valeurs initiales
- // Restaurer les valeurs
- cAmbient = cbAmbient;
- cBack = cbBack;
-
- // Repositionner les états du pipe D3D
- vSetD3DState();
-
- // Repositionner les curseurs des sliders
- Si.fMask = SIF_POS;
- Si.nPos = (cAmbient & 0xff0000) >> 16; SetScrollInfo(GetDlgItem(hWnd, IDC_RA), SB_CTL, &Si, TRUE);
- Si.nPos = (cAmbient & 0xff00) >> 8; SetScrollInfo(GetDlgItem(hWnd, IDC_GA), SB_CTL, &Si, TRUE);
- Si.nPos = cAmbient & 0xff; SetScrollInfo(GetDlgItem(hWnd, IDC_BA), SB_CTL, &Si, TRUE);
- Si.nPos = (cBack & 0xff0000) >> 16; SetScrollInfo(GetDlgItem(hWnd, IDC_RF), SB_CTL, &Si, TRUE);
- Si.nPos = (cBack & 0xff00) >> 8; SetScrollInfo(GetDlgItem(hWnd, IDC_GF), SB_CTL, &Si, TRUE);
- Si.nPos = cBack & 0xff; SetScrollInfo(GetDlgItem(hWnd, IDC_BF), SB_CTL, &Si, TRUE);
- break;
-
- case IDCANCEL: // Restaurer les valeurs initiales et quitter
- // Restaurer les valeurs
- cAmbient = cbAmbient;
- cBack = cbBack;
-
- // Repositionner les états du pipe D3D
- vSetD3DState();
- vForce3DRefresh(XDC_MODE_COMPLET);
-
- // ATTENTION pas de break, on continue...
-
- case IDOK: // Fin dialogue
- EndDialog(hWnd, 0);
- break;
- }
- return TRUE;
- break;
-
- case WM_HSCROLL : // Scroll slider
- // Récupérer les valeurs de scroll
- nScrollCode = (int) LOWORD(wParam); // scroll bar value
- nPos = (short int) HIWORD(wParam); // scroll box position
- hwndScrollBar = (HWND) lParam; // handle to scroll bar
-
- // Si scrolling slider
- if (nScrollCode == SB_THUMBTRACK)
- {
- switch(GetDlgCtrlID(hwndScrollBar))
- {
- case IDC_RA :
- cAmbient &= 0xff00ffff;
- cAmbient |= nPos << 16;
- // Mettre à jour les variables d'état du pipe D3D
- vSetD3DState();
- break;
- case IDC_GA :
- cAmbient &= 0xffff00ff;
- cAmbient |= nPos << 8;
- // Mettre à jour les variables d'état du pipe D3D
- vSetD3DState();
- break;
- case IDC_BA :
- cAmbient &= 0xffffff00;
- cAmbient |= nPos;
- // Mettre à jour les variables d'état du pipe D3D
- vSetD3DState();
- break;
- case IDC_RF :
- cBack &= 0xff00ffff;
- cBack |= nPos << 16;
- break;
- case IDC_GF :
- cBack &= 0xffff00ff;
- cBack |= nPos << 8;
- break;
- case IDC_BF :
- cBack &= 0xffffff00;
- cBack |= nPos;
- break;
- }
-
- // Ajuster la position du slider
- Si.fMask = SIF_POS;
- Si.nPos = nPos;
- SetScrollInfo(GetDlgItem(hWnd, GetDlgCtrlID(hwndScrollBar)), SB_CTL, &Si, TRUE);
-
- // Redessiner la 3D
- vSetD3DState();
- vForce3DRefresh(XDC_MODE_COMPLET);
-
- }
- return TRUE;
- break;
-
- case WM_INITDIALOG :
- // Positionner les sliders
- Si.fMask = SIF_POS | SIF_RANGE;
- Si.nMin = 0;
- Si.nMax = 255;
-
- Si.nPos = (cAmbient & 0xff0000) >> 16; SetScrollInfo(GetDlgItem(hWnd, IDC_RA), SB_CTL, &Si, TRUE);
- Si.nPos = (cAmbient & 0xff00) >> 8; SetScrollInfo(GetDlgItem(hWnd, IDC_GA), SB_CTL, &Si, TRUE);
- Si.nPos = cAmbient & 0xff; SetScrollInfo(GetDlgItem(hWnd, IDC_BA), SB_CTL, &Si, TRUE);
- Si.nPos = (cBack & 0xff0000) >> 16; SetScrollInfo(GetDlgItem(hWnd, IDC_RF), SB_CTL, &Si, TRUE);
- Si.nPos = (cBack & 0xff00) >> 8; SetScrollInfo(GetDlgItem(hWnd, IDC_GF), SB_CTL, &Si, TRUE);
- Si.nPos = cBack & 0xff; SetScrollInfo(GetDlgItem(hWnd, IDC_BF), SB_CTL, &Si, TRUE);
-
- // Mémoriser les valeurs initiales
- cbAmbient = cAmbient;
- cbBack = cBack;
- return TRUE;
- break;
- }
-
- return FALSE;
- }
-
- // Gestion du dialog expand
- BOOL CALLBACK bExpandDlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
- {
- int wmId, wmEvent, nScrollCode, nPos;
- HWND hwndScrollBar;
- int iCnt;
- static D3DVECTOR dVect;
- int iLock = 0;
- char cVal[5];
- static int iExpandLock;
- float fExpandFactor;
-
- Si.cbSize = sizeof(Si);
-
- switch( uMsg )
- {
- case WM_COMMAND :
- wmId = LOWORD(wParam); // Remember, these are...
- wmEvent = HIWORD(wParam); // ...different for Win32!
-
- switch (wmId)
- {
- case IDAPPLY:
- goto __ExpandInit;
-
- case IDCANCEL: // Quitter
- case IDRESET:
- for (iCnt = 0 ; iCnt <= iVertLastUsed ; iCnt++)
- if (bIsVertexSelected(iCnt))
- Vertices[iCnt].vPoint = Vertices[iCnt].vPointBack;
- for (iCnt = 0 ; iCnt <= iTriaLastUsed ; iCnt++)
- if (bIsTrianglePartiallySelected(iCnt))
- bUpdateD3DTri(iCnt);
- vForce2DRefresh(XDC_MODE_COMPLET);
- vForce3DRefresh(XDC_MODE_COMPLET);
- if (wmId == IDRESET) goto __ExpandInitSliders;
-
- case IDOK: // Appliquer les modifs
- EndDialog(hWnd, 0);
- break;
-
- case IDC_LOCK:
- iExpandLock = SendDlgItemMessage(hWnd, IDC_LOCK, BM_GETCHECK, (WPARAM) 0, 0L);
- break;
- }
- return TRUE;
-
- case WM_HSCROLL : // Scroll slider
- // Récupérer les valeurs de scroll
- nScrollCode = (int) LOWORD(wParam); // scroll bar value
- nPos = (short int) HIWORD(wParam); // scroll box position
- hwndScrollBar = (HWND) lParam; // handle to scroll bar
-
- // Si scrolling slider
- if (nScrollCode == SB_THUMBTRACK)
- {
- sprintf(cVal, "%d%%", nPos);
- fExpandFactor = (float) nPos / 100.f;
- Si.fMask = SIF_POS;
- Si.nPos = nPos;
-
- if (iExpandLock)
- {
- for (iCnt = 0 ; iCnt <= iVertLastUsed ; iCnt++)
- if (bIsVertexSelected(iCnt))
- {
- Vertices[iCnt].vPoint.x = dVect.x + (Vertices[iCnt].vPointBack.x - dVect.x) * fExpandFactor;
- Vertices[iCnt].vPoint.y = dVect.y + (Vertices[iCnt].vPointBack.y - dVect.y) * fExpandFactor;
- Vertices[iCnt].vPoint.z = dVect.z + (Vertices[iCnt].vPointBack.z - dVect.z) * fExpandFactor;
- }
-
- SendDlgItemMessage(hWnd, IDC_EXV, WM_SETTEXT, 0, (long)&cVal[0]);
- SendDlgItemMessage(hWnd, IDC_EYV, WM_SETTEXT, 0, (long)&cVal[0]);
- SendDlgItemMessage(hWnd, IDC_EZV, WM_SETTEXT, 0, (long)&cVal[0]);
- SetScrollInfo(GetDlgItem(hWnd, IDC_EX), SB_CTL, &Si, TRUE);
- SetScrollInfo(GetDlgItem(hWnd, IDC_EY), SB_CTL, &Si, TRUE);
- SetScrollInfo(GetDlgItem(hWnd, IDC_EZ), SB_CTL, &Si, TRUE);
- }
- else
- {
- switch(GetDlgCtrlID(hwndScrollBar))
- {
- case IDC_EX :
- SendDlgItemMessage(hWnd, IDC_EXV, WM_SETTEXT, 0, (long)&cVal[0]);
- for (iCnt = 0 ; iCnt <= iVertLastUsed ; iCnt++)
- if (bIsVertexSelected(iCnt))
- Vertices[iCnt].vPoint.x = dVect.x + (Vertices[iCnt].vPointBack.x - dVect.x) * fExpandFactor;
- break;
- case IDC_EY :
- SendDlgItemMessage(hWnd, IDC_EYV, WM_SETTEXT, 0, (long)&cVal[0]);
- for (iCnt = 0 ; iCnt <= iVertLastUsed ; iCnt++)
- if (bIsVertexSelected(iCnt))
- Vertices[iCnt].vPoint.y = dVect.y + (Vertices[iCnt].vPointBack.y - dVect.y) * fExpandFactor;
- break;
- case IDC_EZ :
- SendDlgItemMessage(hWnd, IDC_EZV, WM_SETTEXT, 0, (long)&cVal[0]);
- for (iCnt = 0 ; iCnt <= iVertLastUsed ; iCnt++)
- if (bIsVertexSelected(iCnt))
- Vertices[iCnt].vPoint.z = dVect.z + (Vertices[iCnt].vPointBack.z - dVect.z) * fExpandFactor;
- break;
- }
- SetScrollInfo(GetDlgItem(hWnd, GetDlgCtrlID(hwndScrollBar)), SB_CTL, &Si, TRUE);
- }
-
- // Redessiner la 3D
- for (iCnt = 0 ; iCnt <= iTriaLastUsed ; iCnt++)
- if (bIsTrianglePartiallySelected(iCnt))
- bUpdateD3DTri(iCnt);
- vForce2DRefresh(XDC_MODE_COMPLET);
- vForce3DRefresh(XDC_MODE_COMPLET);
- }
- return TRUE;
-
- case WM_INITDIALOG :
- SendDlgItemMessage(hWnd, IDC_LOCK, BM_SETCHECK, (WPARAM) iExpandLock, 0L);
-
- __ExpandInit:
- // Déterminer le barycentre de la sélection (on travaille par rapport à lui)
- dVect = vCenter();
-
- __ExpandInitSliders:
- // Positionner les sliders
- Si.fMask = SIF_POS | SIF_RANGE;
- Si.nMin = 0; // Mini
- Si.nMax = 200; // Maxi
- Si.nPos = 100; // Position initiale
- sprintf(cVal, "%d%%", Si.nPos);
-
- SetScrollInfo(GetDlgItem(hWnd, IDC_EX), SB_CTL, &Si, TRUE); SendDlgItemMessage(hWnd, IDC_EXV, WM_SETTEXT, 0, (long)&cVal[0]);
- SetScrollInfo(GetDlgItem(hWnd, IDC_EY), SB_CTL, &Si, TRUE); SendDlgItemMessage(hWnd, IDC_EYV, WM_SETTEXT, 0, (long)&cVal[0]);
- SetScrollInfo(GetDlgItem(hWnd, IDC_EZ), SB_CTL, &Si, TRUE); SendDlgItemMessage(hWnd, IDC_EZV, WM_SETTEXT, 0, (long)&cVal[0]);
-
- return TRUE;
- }
-
- return FALSE;
- }
-
- // Gestion du dialog props sphère
- BOOL CALLBACK bSphereDlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
- {
- int wmId, wmEvent;
- int iH, iV; // Subdivisions horizontales & verticales
- char cBuf[12];
-
- switch( uMsg )
- {
- case WM_COMMAND :
- wmId = LOWORD(wParam); // Remember, these are...
- wmEvent = HIWORD(wParam); // ...different for Win32!
-
- switch (wmId)
- {
- case IDCANCEL:
- EndDialog(hWnd, -1);
- break;
-
- case IDOK: // Fin dialogue
- SendDlgItemMessage(hWnd, IDC_SH, WM_GETTEXT, sizeof(cBuf) - 1, (LPARAM) cBuf); iH = atoi(cBuf);
- SendDlgItemMessage(hWnd, IDC_SV, WM_GETTEXT, sizeof(cBuf) - 1, (LPARAM) cBuf); iV = atoi(cBuf);
- if ((iH > 0) && (iV > 0))
- EndDialog(hWnd, iV << 16 | iH);
- else
- {
- vTrace("*** E0008 : définition impossible (SH : %d, sV : %d)", iH, iV);
- EndDialog(hWnd, -1);
- }
- break;
- }
- return TRUE;
- break;
-
- case WM_INITDIALOG :
- iH = HIWORD(lParam); sprintf(cBuf, "%d", iH); SendDlgItemMessage(hWnd, IDC_SH, WM_SETTEXT, 0, (LPARAM) cBuf);
- iV = LOWORD(lParam); sprintf(cBuf, "%d", iV); SendDlgItemMessage(hWnd, IDC_SV, WM_SETTEXT, 0, (LPARAM) cBuf);
- return TRUE;
- break;
- }
-
- return FALSE;
- }
-
- // Gestion du dialog props répliquer hélice
- BOOL CALLBACK bHelixDlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
- {
- int wmId;
- static int iRot, iTrans, iDP, iAP, iP; // Degrés par pas, avance par pas, nombre de pas
- static BOOL bLierClones = TRUE;
- char cBuf[12];
- D3DVECTOR vShift = D3DVECTOR(0.f, 0.f, 0.f);;
- D3DMATRIX mRot;
- float fAngle;
-
- switch( uMsg )
- {
- case WM_COMMAND :
- wmId = LOWORD(wParam);
-
- switch (wmId)
- {
- // Bouton lier clones
- case IDC_LCL:
- bLierClones = SendDlgItemMessage(hWnd, IDC_LCL, BM_GETCHECK, (WPARAM) 0, 0L);
- break;
-
- // Boutons sélection rotation autour axe X/Y/Z...
- case IDC_RX:
- case IDC_RY:
- case IDC_RZ:
- iRot = wmId;
- break;
-
- // Boutons sélection translation autour axe X/Y/Z...
- case IDC_TX:
- case IDC_TY:
- case IDC_TZ:
- iTrans = wmId;
- break;
-
- // Annuler
- case IDCANCEL:
- EndDialog(hWnd, -1);
- break;
-
- // Appliquer la transformation
- case IDOK:
- // Récupérer l'angle par pas, l'avance par pas, le nombre de pas
- SendDlgItemMessage(hWnd, IDC_DP, WM_GETTEXT, sizeof(cBuf) - 1, (LPARAM) cBuf); iDP = atoi(cBuf);
- SendDlgItemMessage(hWnd, IDC_AP, WM_GETTEXT, sizeof(cBuf) - 1, (LPARAM) cBuf); iAP = atoi(cBuf);
- SendDlgItemMessage(hWnd, IDC_P, WM_GETTEXT, sizeof(cBuf) - 1, (LPARAM) cBuf); iP = atoi(cBuf);
-
- // Moduler l'angle @360°
- iDP = iDP % 360;
-
- // Calculer l'angle en radians
- fAngle = g_2_PI * (float) iDP / 360.f;
-
- // Si moins de 1 pas stop
- if (iP < 1) EndDialog(hWnd, -1);
-
- // Calculer la matrice de rotation en fonction de l'axe et de l'angle choisis
- switch(iRot)
- {
- case IDC_RY : D3DUtil_SetRotateYMatrix(mRot, -fAngle); break;
- case IDC_RZ : D3DUtil_SetRotateZMatrix(mRot, fAngle); break;
- case IDC_RX : D3DUtil_SetRotateXMatrix(mRot, -fAngle); break;
- }
-
- // Calculer le vecteur d'avance en fonction de l'axe et de l'avance
- switch(iTrans)
- {
- case IDC_TY : vShift.y += ((float) iAP / 10.f); break;
- case IDC_TZ : vShift.z += ((float) iAP / 10.f); break;
- case IDC_TX : vShift.x += ((float) iAP / 10.f); break;
- }
-
- // Pour chaque pas...
- for (int iPas = 0 ; iPas < iP ; iPas ++)
- {
- // Préparer un clone de la sélection, qui se retrouve sélectionné (en désélectionnant le reste)
- bCloneSelection(vShift, bLierClones ? XDC_MODE_EXTRUDE : XDC_MODE_CLONE);
-
- // Appliquer la matrice aux sommets sélectionnés
- for (int iVert = 0 ; iVert <= iVertLastUsed ; iVert++)
- if (bIsVertexSelected(iVert))
- {
- // Changer de repère => Cursor1
- D3DVECTOR vTrans = Vertices[iVert].vPoint - Cursor1;
-
- // Appliquer la rotation au point translaté
- D3DMath_VectorMatrixMultiply(vTrans,
- vTrans,
- mRot);
-
- // Remettre dans le repère d'origine
- Vertices[iVert].vPoint = vTrans + Cursor1;
- }
-
- // Recalculer les sommets des triangles ayant des sommets sélectionnés
- for (int iTriangle = 0 ; iTriangle <= iTriaLastUsed ; iTriangle++)
- if (bIsTrianglePartiallySelected(iTriangle))
- bUpdateD3DTri(iTriangle);
- }
-
- // Redessiner la 2D
- vForce2DRefresh(XDC_MODE_COMPLET);
- // Redessiner la 3D
- vForce3DRefresh(XDC_MODE_COMPLET);
-
- EndDialog(hWnd, 0);
- break;
- }
- return TRUE;
-
- case WM_INITDIALOG :
- switch(lWActive)
- {
- case XDC_WID_TOP : // X et Z
- iRot = IDC_RY;
- iTrans = IDC_TY;
- break;
-
- case XDC_WID_FACE : // X et Y
- iRot = IDC_RZ;
- iTrans = IDC_TZ;
- break;
-
- case XDC_WID_SIDE : // Z et Y
- iRot = IDC_RX;
- iTrans = IDC_TX;
- break;
- }
-
- SendDlgItemMessage(hWnd, IDC_LCL, BM_SETCHECK, (WPARAM) bLierClones, 0L);
- SendDlgItemMessage(hWnd, iRot, BM_SETCHECK, (WPARAM) 1, 0L);
- SendDlgItemMessage(hWnd, iTrans, BM_SETCHECK, (WPARAM) 1, 0L);
-
- sprintf(cBuf, "%d", iDP); SendDlgItemMessage(hWnd, IDC_DP, WM_SETTEXT, 0, (LPARAM) cBuf);
- sprintf(cBuf, "%d", iAP); SendDlgItemMessage(hWnd, IDC_AP, WM_SETTEXT, 0, (LPARAM) cBuf);
- sprintf(cBuf, "%d", iP); SendDlgItemMessage(hWnd, IDC_P, WM_SETTEXT, 0, (LPARAM) cBuf);
- return TRUE;
- }
- return FALSE;
- }
-
-
- // Gestion du dialog facettes
- BOOL CALLBACK bFaceDlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
- {
- int wmId, wmEvent, nScrollCode, nPos, iCnt;
- HWND hwndScrollBar;
- char cVal[5];
- float fValue;
-
- Si.cbSize = sizeof(Si);
-
- switch( uMsg )
- {
- case WM_COMMAND :
- wmId = LOWORD(wParam); // Remember, these are...
- wmEvent = HIWORD(wParam); // ...different for Win32!
-
- switch (wmId)
- {
- case IDCANCEL:
- case IDOK: // Fin dialogue
- EndDialog(hWnd, -1);
- break;
- }
- return TRUE;
- break;
-
- case WM_HSCROLL : // Scroll slider
- // Récupérer les valeurs de scroll
- nScrollCode = (int) LOWORD(wParam); // scroll bar value
- nPos = (short int) HIWORD(wParam); // scroll box position
- hwndScrollBar = (HWND) lParam; // handle to scroll bar
-
- // Si scrolling slider
- if (nScrollCode == SB_THUMBTRACK)
- {
- fValue = (float) nPos / 100.f;
-
- for (int iTriangle = 0 ; iTriangle <= iTriaLastUsed ; iTriangle++)
- if (bIsTriangleSelected(iTriangle))
- {
- D3DMATERIAL7 *pMtrl = &(Materials[Triangles[iTriangle].iMtrl].mtrl);
- switch(GetDlgCtrlID(hwndScrollBar))
- {
- case IDC_D_A: pMtrl -> diffuse.a = fValue; sprintf(cVal, "A %d%%", Si.nPos); SendDlgItemMessage(hWnd, IDV_D_A, WM_SETTEXT, 0, (long)&cVal[0]); break;
- case IDC_D_R: pMtrl -> diffuse.r = fValue; sprintf(cVal, "R %d%%", Si.nPos); SendDlgItemMessage(hWnd, IDV_D_R, WM_SETTEXT, 0, (long)&cVal[0]); break;
- case IDC_D_G: pMtrl -> diffuse.g = fValue; sprintf(cVal, "G %d%%", Si.nPos); SendDlgItemMessage(hWnd, IDV_D_G, WM_SETTEXT, 0, (long)&cVal[0]); break;
- case IDC_D_B: pMtrl -> diffuse.b = fValue; sprintf(cVal, "B %d%%", Si.nPos); SendDlgItemMessage(hWnd, IDV_D_B, WM_SETTEXT, 0, (long)&cVal[0]); break;
-
- case IDC_A_A: pMtrl -> ambient.a = fValue; sprintf(cVal, "A %d%%", Si.nPos); SendDlgItemMessage(hWnd, IDV_A_A, WM_SETTEXT, 0, (long)&cVal[0]); break;
- case IDC_A_R: pMtrl -> ambient.r = fValue; sprintf(cVal, "R %d%%", Si.nPos); SendDlgItemMessage(hWnd, IDV_A_R, WM_SETTEXT, 0, (long)&cVal[0]); break;
- case IDC_A_G: pMtrl -> ambient.g = fValue; sprintf(cVal, "G %d%%", Si.nPos); SendDlgItemMessage(hWnd, IDV_A_G, WM_SETTEXT, 0, (long)&cVal[0]); break;
- case IDC_A_B: pMtrl -> ambient.b = fValue; sprintf(cVal, "B %d%%", Si.nPos); SendDlgItemMessage(hWnd, IDV_A_B, WM_SETTEXT, 0, (long)&cVal[0]); break;
-
- case IDC_S_A: pMtrl -> specular.a = fValue; sprintf(cVal, "A %d%%", Si.nPos); SendDlgItemMessage(hWnd, IDV_S_A, WM_SETTEXT, 0, (long)&cVal[0]); break;
- case IDC_S_R: pMtrl -> specular.r = fValue; sprintf(cVal, "R %d%%", Si.nPos); SendDlgItemMessage(hWnd, IDV_S_R, WM_SETTEXT, 0, (long)&cVal[0]); break;
- case IDC_S_G: pMtrl -> specular.g = fValue; sprintf(cVal, "G %d%%", Si.nPos); SendDlgItemMessage(hWnd, IDV_S_G, WM_SETTEXT, 0, (long)&cVal[0]); break;
- case IDC_S_B: pMtrl -> specular.b = fValue; sprintf(cVal, "B %d%%", Si.nPos); SendDlgItemMessage(hWnd, IDV_S_B, WM_SETTEXT, 0, (long)&cVal[0]); break;
- case IDC_S_P: pMtrl -> power = fValue; sprintf(cVal, "P %d%%", Si.nPos); SendDlgItemMessage(hWnd, IDV_S_P, WM_SETTEXT, 0, (long)&cVal[0]); break;
-
- case IDC_E_A: pMtrl -> emissive.a = fValue; sprintf(cVal, "A %d%%", Si.nPos); SendDlgItemMessage(hWnd, IDV_E_A, WM_SETTEXT, 0, (long)&cVal[0]); break;
- case IDC_E_R: pMtrl -> emissive.r = fValue; sprintf(cVal, "R %d%%", Si.nPos); SendDlgItemMessage(hWnd, IDV_E_R, WM_SETTEXT, 0, (long)&cVal[0]); break;
- case IDC_E_G: pMtrl -> emissive.g = fValue; sprintf(cVal, "G %d%%", Si.nPos); SendDlgItemMessage(hWnd, IDV_E_G, WM_SETTEXT, 0, (long)&cVal[0]); break;
- case IDC_E_B: pMtrl -> emissive.b = fValue; sprintf(cVal, "B %d%%", Si.nPos); SendDlgItemMessage(hWnd, IDV_E_B, WM_SETTEXT, 0, (long)&cVal[0]); break;
- }
- }
- Si.fMask = SIF_POS;
- Si.nPos = nPos;
- SetScrollInfo(GetDlgItem(hWnd, GetDlgCtrlID(hwndScrollBar)), SB_CTL, &Si, TRUE);
-
- // Redessiner la 3D
- vForce3DRefresh(XDC_MODE_COMPLET);
- }
- return TRUE;
-
- case WM_INITDIALOG :
- // Positionner les sliders sur la moyenne de la sélection
- Si.fMask = SIF_POS | SIF_RANGE;
- Si.nMin = 0; // Mini
- Si.nMax = 100; // Maxi
-
- {
- D3DMATERIAL7 Mtrl;
- ZeroMemory(&Mtrl, sizeof(D3DMATERIAL7));
-
- iCnt = 0;
-
- for (int iTriangle = 0 ; iTriangle <= iTriaLastUsed ; iTriangle++)
- if (bIsTriangleSelected(iTriangle))
- {
- D3DMATERIAL7 *pMtrl = &(Materials[Triangles[iTriangle].iMtrl].mtrl);
- iCnt++;
- Mtrl.diffuse.a += pMtrl -> diffuse.a;
- Mtrl.diffuse.r += pMtrl -> diffuse.r;
- Mtrl.diffuse.g += pMtrl -> diffuse.g;
- Mtrl.diffuse.b += pMtrl -> diffuse.b;
-
- Mtrl.ambient.a += pMtrl -> ambient.a;
- Mtrl.ambient.r += pMtrl -> ambient.r;
- Mtrl.ambient.g += pMtrl -> ambient.g;
- Mtrl.ambient.b += pMtrl -> ambient.b;
-
- Mtrl.specular.a += pMtrl -> specular.a;
- Mtrl.specular.r += pMtrl -> specular.r;
- Mtrl.specular.g += pMtrl -> specular.g;
- Mtrl.specular.b += pMtrl -> specular.b;
- Mtrl.power += pMtrl -> power;
-
- Mtrl.emissive.a += pMtrl -> emissive.a;
- Mtrl.emissive.r += pMtrl -> emissive.r;
- Mtrl.emissive.g += pMtrl -> emissive.g;
- Mtrl.emissive.b += pMtrl -> emissive.b;
- }
-
- if (iCnt == 0) iCnt = 1;
-
- Si.nPos = (int) (100.f * Mtrl.diffuse.a / iCnt); sprintf(cVal, "A %d%%", Si.nPos); SetScrollInfo(GetDlgItem(hWnd, IDC_D_A), SB_CTL, &Si, TRUE); SendDlgItemMessage(hWnd, IDV_D_A, WM_SETTEXT, 0, (long)&cVal[0]);
- Si.nPos = (int) (100.f * Mtrl.diffuse.r / iCnt); sprintf(cVal, "R %d%%", Si.nPos); SetScrollInfo(GetDlgItem(hWnd, IDC_D_R), SB_CTL, &Si, TRUE); SendDlgItemMessage(hWnd, IDV_D_R, WM_SETTEXT, 0, (long)&cVal[0]);
- Si.nPos = (int) (100.f * Mtrl.diffuse.g / iCnt); sprintf(cVal, "G %d%%", Si.nPos); SetScrollInfo(GetDlgItem(hWnd, IDC_D_G), SB_CTL, &Si, TRUE); SendDlgItemMessage(hWnd, IDV_D_G, WM_SETTEXT, 0, (long)&cVal[0]);
- Si.nPos = (int) (100.f * Mtrl.diffuse.b / iCnt); sprintf(cVal, "B %d%%", Si.nPos); SetScrollInfo(GetDlgItem(hWnd, IDC_D_B), SB_CTL, &Si, TRUE); SendDlgItemMessage(hWnd, IDV_D_B, WM_SETTEXT, 0, (long)&cVal[0]);
-
- Si.nPos = (int) (100.f * Mtrl.ambient.a / iCnt); sprintf(cVal, "A %d%%", Si.nPos); SetScrollInfo(GetDlgItem(hWnd, IDC_A_A), SB_CTL, &Si, TRUE); SendDlgItemMessage(hWnd, IDV_A_A, WM_SETTEXT, 0, (long)&cVal[0]);
- Si.nPos = (int) (100.f * Mtrl.ambient.r / iCnt); sprintf(cVal, "R %d%%", Si.nPos); SetScrollInfo(GetDlgItem(hWnd, IDC_A_R), SB_CTL, &Si, TRUE); SendDlgItemMessage(hWnd, IDV_A_R, WM_SETTEXT, 0, (long)&cVal[0]);
- Si.nPos = (int) (100.f * Mtrl.ambient.g / iCnt); sprintf(cVal, "G %d%%", Si.nPos); SetScrollInfo(GetDlgItem(hWnd, IDC_A_G), SB_CTL, &Si, TRUE); SendDlgItemMessage(hWnd, IDV_A_G, WM_SETTEXT, 0, (long)&cVal[0]);
- Si.nPos = (int) (100.f * Mtrl.ambient.b / iCnt); sprintf(cVal, "B %d%%", Si.nPos); SetScrollInfo(GetDlgItem(hWnd, IDC_A_B), SB_CTL, &Si, TRUE); SendDlgItemMessage(hWnd, IDV_A_B, WM_SETTEXT, 0, (long)&cVal[0]);
-
- Si.nPos = (int) (100.f * Mtrl.specular.a / iCnt); sprintf(cVal, "A %d%%", Si.nPos); SetScrollInfo(GetDlgItem(hWnd, IDC_S_A), SB_CTL, &Si, TRUE); SendDlgItemMessage(hWnd, IDV_S_A, WM_SETTEXT, 0, (long)&cVal[0]);
- Si.nPos = (int) (100.f * Mtrl.specular.r / iCnt); sprintf(cVal, "R %d%%", Si.nPos); SetScrollInfo(GetDlgItem(hWnd, IDC_S_R), SB_CTL, &Si, TRUE); SendDlgItemMessage(hWnd, IDV_S_R, WM_SETTEXT, 0, (long)&cVal[0]);
- Si.nPos = (int) (100.f * Mtrl.specular.g / iCnt); sprintf(cVal, "G %d%%", Si.nPos); SetScrollInfo(GetDlgItem(hWnd, IDC_S_G), SB_CTL, &Si, TRUE); SendDlgItemMessage(hWnd, IDV_S_G, WM_SETTEXT, 0, (long)&cVal[0]);
- Si.nPos = (int) (100.f * Mtrl.specular.b / iCnt); sprintf(cVal, "B %d%%", Si.nPos); SetScrollInfo(GetDlgItem(hWnd, IDC_S_B), SB_CTL, &Si, TRUE); SendDlgItemMessage(hWnd, IDV_S_B, WM_SETTEXT, 0, (long)&cVal[0]);
- Si.nPos = (int) (100.f * Mtrl.power / iCnt); sprintf(cVal, "P %d%%", Si.nPos); SetScrollInfo(GetDlgItem(hWnd, IDC_S_P), SB_CTL, &Si, TRUE); SendDlgItemMessage(hWnd, IDV_S_P, WM_SETTEXT, 0, (long)&cVal[0]);
-
- Si.nPos = (int) (100.f * Mtrl.emissive.a / iCnt); sprintf(cVal, "A %d%%", Si.nPos); SetScrollInfo(GetDlgItem(hWnd, IDC_E_A), SB_CTL, &Si, TRUE); SendDlgItemMessage(hWnd, IDV_E_A, WM_SETTEXT, 0, (long)&cVal[0]);
- Si.nPos = (int) (100.f * Mtrl.emissive.r / iCnt); sprintf(cVal, "R %d%%", Si.nPos); SetScrollInfo(GetDlgItem(hWnd, IDC_E_R), SB_CTL, &Si, TRUE); SendDlgItemMessage(hWnd, IDV_E_R, WM_SETTEXT, 0, (long)&cVal[0]);
- Si.nPos = (int) (100.f * Mtrl.emissive.g / iCnt); sprintf(cVal, "G %d%%", Si.nPos); SetScrollInfo(GetDlgItem(hWnd, IDC_E_G), SB_CTL, &Si, TRUE); SendDlgItemMessage(hWnd, IDV_E_G, WM_SETTEXT, 0, (long)&cVal[0]);
- Si.nPos = (int) (100.f * Mtrl.emissive.b / iCnt); sprintf(cVal, "B %d%%", Si.nPos); SetScrollInfo(GetDlgItem(hWnd, IDC_E_B), SB_CTL, &Si, TRUE); SendDlgItemMessage(hWnd, IDV_E_B, WM_SETTEXT, 0, (long)&cVal[0]);
- }
-
- return TRUE;
- }
-
- return FALSE;
- }
-
- // Gestion du dialog trous dans forme à remplir
- BOOL CALLBACK bHoleDlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
- {
- int wmId, wmEvent;
- char cBuf[12];
-
- switch( uMsg )
- {
- case WM_COMMAND :
- wmId = LOWORD(wParam); // Remember, these are...
- wmEvent = HIWORD(wParam); // ...different for Win32!
-
- switch (wmId)
- {
- case IDC_FADE:
- bFillAndRemoveEdges = (bFillAndRemoveEdges ? FALSE : TRUE);
- goto _HUpdate;
- break;
-
- case IDRESET:
- iHoles = 0;
- goto _HUpdate;
- break;
-
- case IDOK: // Fin dialogue
- hHoleDlgActive = NULL;
- SendDlgItemMessage(hWnd, IDC_SH, WM_GETTEXT, sizeof(cBuf) - 1, (LPARAM) cBuf); iHoles = atoi(cBuf);
- if (iHoles >= XDC_MAX_HOLES)
- {
- vTrace("*** E0009 : trop de trous");
- iHoles = 0;
- }
- EndDialog(hWnd, 0);
- break;
- }
- return TRUE;
- break;
-
- case WM_INITDIALOG :
- hHoleDlgActive = hWnd;
- iHoles = 0;
-
- case WM_USER + 1:
- _HUpdate:
- SendDlgItemMessage(hWnd, IDC_FADE, BM_SETCHECK, (WPARAM) bFillAndRemoveEdges, 0L);
- sprintf(cBuf, "%d", iHoles); SendDlgItemMessage(hWnd, IDC_SH, WM_SETTEXT, 0, (LPARAM) cBuf);
- SetForegroundWindow(hWnd);
- return TRUE;
- }
-
- return FALSE;
- }
-
- // Gestion du dialog props sphère
- BOOL CALLBACK bStringDlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
- {
- int wmId, wmEvent;
-
- switch( uMsg )
- {
- case WM_COMMAND :
- wmId = LOWORD(wParam); // Remember, these are...
- wmEvent = HIWORD(wParam); // ...different for Win32!
-
- switch (wmId)
- {
- case IDCANCEL:
- EndDialog(hWnd, -1);
- break;
-
- case IDOK: // Fin dialogue
- SendDlgItemMessage(hWnd, IDC_SH, WM_GETTEXT, sizeof(cString) - 1, (LPARAM) cString);
- EndDialog(hWnd, 0);
- break;
- }
- return TRUE;
- break;
-
- case WM_INITDIALOG :
- SendDlgItemMessage(hWnd, IDC_SH, WM_SETTEXT, 0, (LPARAM) cString);
- return TRUE;
- break;
- }
-
- return FALSE;
- }
-
-